// import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/storage'
import { getUserInfo } from '@/api/user'
export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      setToken(token)
    },
    removeToken (state) {
      removeToken()
      state.token = {}
    },
    setUserInfo (state, payload) {
      state.userInfo = payload
      // console.log(state.userInfo)
    }
  },
  actions: {
    // async login (context, payload) {
    //   const res = await login(payload.mobile, payload.code)
    //   context.commit('setToken', res.data)
    // }
    async getUserInfo (context) {
      const res = await getUserInfo()
      context.commit('setUserInfo', res.data)
    }
  }
}
